var express = require("express");
var router = express.Router();
var homehot = require("./home/homehot.js");
var homehot2 = require("./home/homehot2.js");
var axf_index = require('./axf/index.js');
var searchData = require("./search/index.js");

var homeindex = require("./home/index.js");
var roommate = require('./home/roommate');
var currentpage = require('./home/currentpage.js'); 
var housedetail = require('./home/detail');

// --------------------------生活服务-------------------------
var cleanData = require("./LifeService/clean.js");
var homeRemoveData = require("./LifeService/homeremove.js");
var homeRepairData = require("./LifeService/HomeRepair.js");
var rechargeData = require("./LifeService/recharge.js");
var dayCleanData = require("./LifeService/dayClean.js");
var acarusData = require("./LifeService/AcarusKilling.js");

var url = require("url");

// 解决跨域问题
/*
router.all("/web1807",function(req, res, next){
  // 跨域处理
  res.header("Access-Control-Allow-Origin", "*");
  next();
})
*/

router.all("/api/homehot", function(req, res, next) {
  // 跨域处理
  res.header("Access-Control-Allow-Origin", "*");
  next();
});
router.all("/api/axf_index", function(req, res, next) {
  // 跨域处理
  res.header("Access-Control-Allow-Origin", "*");
  next();
});
router.all("/api/homehot2", function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  next();
});
router.all("/api/search", function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  next();
});
router.all("/api/free/search", function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  next();
});

router.get("/api/axf_index", function(req, res) {
  // var query = url.parse(req.url, true).query;
  // console.log("城市:" + query.city);
  res.send(axf_index);
})

router.get("/api/homehot", function(req, res) {
  var query = url.parse(req.url, true).query;
  console.log("城市:" + query.city);
  res.send(homehot)
})

router.get("/api/homehot2", function(req, res) {
  var query = url.parse(req.url, true).query;
  console.log("城市:" + query.city);
  res.send(homehot2)
})

// 搜索字段
router.get("/api/search", function(req, res) {
  // 搜索内容  page页码
  var path_url = url.parse(req.url, true);
  var query = path_url.query;
  console.log("当前城市:" + query.city);
  console.log("当前页数:" + query.page);
  console.log("搜索内容:" + query.keywords);
  res.send(searchData)
})

// 豪宅  整租   合租
router.get("/api/free/search", function(req, res) {
  // 搜索内容  page页码
  var path_url = url.parse(req.url, true);
  var query = path_url.query;
  console.log("当前城市:" + query.city);
  console.log("当前页数:" + query.page);
  res.send(searchData)
})


//home data request
//首页热门房源
router.get("/api/homeindex",function(req,res){
  // 城市  page页码
  var path_url = url.parse(req.url,true);
  var query = path_url.query;
  console.log("当前城市:"+query.cityName);
  console.log("当前页数:"+query.page);
  res.send(homeindex);
})

//找室友，合租信息
router.get("/api/roommate",function(req,res){
  // 城市  page页码
  var path_url = url.parse(req.url,true);
  var query = path_url.query;
  console.log("当前城市:"+query.cityName);
  console.log("当前页数:"+query.page);
  res.send(roommate);
})

//首页中当前页房源信息

router.get("/api/currentpage",function(req,res){
  // 城市  page页码
  var path_url = url.parse(req.url,true);
  var query = path_url.query;
  console.log("当前城市:"+query.keyWords);
  console.log("当前页数:"+query.page);
  res.send(currentpage);
})

//房子详情页数据
router.get("/api/housedetail",function (req,res) {
  //房子id
  var query = url.parse(req.url,true).query;
  console.log(query.id);
  res.send(housedetail)
})

// --------------------------生活服务-------------------------

router.get("/api/life",function(req,res){
  // 搜索内容  page页码
  var path_url = url.parse(req.url,true);
  var lifeType = path_url.query.lifeType;
  if(lifeType === '保洁'){
    res.send(cleanData)
  }else if (lifeType === '搬家') {
    res.send(homeRemoveData)
  }else if (lifeType === '家修') {
    res.send(homeRepairData)
  }
})
router.get("/api/recharge",function(req,res){
  var path_url = url.parse(req.url,true);
  var lifeType = path_url.query.userid;
    res.send(rechargeData)
})
router.get("/api/dayclean",function(req,res){
    res.send(dayCleanData)
})
router.get("/api/acarus",function(req,res){
    res.send(acarusData)
})


module.exports = router;
